package com.example.myapplication.hospital;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.OKHttpTool;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.ClassificationofdoctorsBean;
import com.example.myapplication.apter.ClassificationofdoctorsApter;


public class MedicActivity extends AppCompatActivity {

    private String REGISTRATION_ID;
    private ImageView bloak;
    private RecyclerView re_medic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_medic);
        initview();
        //返回
        but_bloak();
        //医生列表
        classificationofdoctors();
    }

    private void classificationofdoctors() {
        OKHttpTool.doNetRequest("prod-api/api/pet-hospital/pet-doctor/list?typeId="+REGISTRATION_ID,
                OKHttpTool.GET,
                ClassificationofdoctorsBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                ClassificationofdoctorsBean classificationofdoctorsBean = (ClassificationofdoctorsBean)obj;
                                if(classificationofdoctorsBean.getCode()==200){
                                    re_medic.setLayoutManager(new LinearLayoutManager(MedicActivity.this));
                                    re_medic.setAdapter(new ClassificationofdoctorsApter(MedicActivity.this,classificationofdoctorsBean.getRows()));
                                }
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void but_bloak() {
        bloak.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MedicActivity.this.finish();
            }
        });
    }

    private void initview() {
        Intent intent = getIntent();
        REGISTRATION_ID = intent.getStringExtra(Commom.REGISTRATION_ID);

        bloak = findViewById(R.id.bloak);
        re_medic = findViewById(R.id.re_medic);
    }
}